<%@page contentType="text/html" pageEncoding="UTF-8" import="consultas.funciones"%>
<%@page import="consultas.Usuarios"%>
<jsp:useBean id="reg" class="consultas.funciones" scope="session" />


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>www.queterifas.com</title>
        <link rel="stylesheet" type="text/css" href="css/estilo.css" media="screen" />
        <script src="jshash-2.2/md5-min.js" type="text/javascript"></script>
        <link href='http://fonts.googleapis.com/css?family=Averia+Sans+Libre' rel='stylesheet' type='text/css'>
        <script type="text/javascript">
            
            function calcMD52(){
            document.getElementById("passnue").value=hex_md5(document.getElementById("passnue").value);
            document.getElementById("passvie").value=hex_md5(document.getElementById("passvie").value);
            }
            
            </script>
            <script>         
            function datosPersonales(){
                var inputs=document.getElementsByTagName('input');
                //document.write(inputs.length);
                for(i=0;i<6;i++){
                    if(i!==4)
                    inputs[i].disabled=false;
                }
            };
            
            function datosContacto(){
                var inputs=document.getElementsByTagName('input');
                //document.write(inputs.length);
                for(i=7;i<14;i++){
                    if(i<8 || i>9)
                    inputs[i].disabled=false;
                }
            };
            
            function passigual(){
                if(document.getElementById('passnue').value==document.getElementById('passnue2').value){
                    alert("contraseñas correctas");
                }
                else{
                    alert("las contraseñas nuevas no coinciden, inténtelo otra vez");
                    document.getElementById('passnue').value="";
                    document.getElementById('passnue2').value="";
                }
                
                
            }
        </script>
        
    </head>
    <body>
        <!-- INCLUDE PARA METER EL HEADER -->
      <jsp:include page="includes/header.jsp"/>
      <section id="contenedor">
          <%
            Usuarios user = reg.consultaUsuario();
          %>
        <br><br>
        
        <script type="text/javascript">
            /*FUNCIONES CON ARRAY PARA LOS DIAS, MESES Y AÑOS DE LA FECHA EN EL FORM*/
	function dias(){
		var dias=31;
                var codigo="<option>Día</option>";
		for(i=1;i<=dias;i++){
			if(i<10)
			codigo+="<option>"+"0"+i+"</option>";
			else
			codigo+="<option>"+i+"</option>";
			}
                document.getElementById("dias").innerHTML=codigo;
		};
		
	function meses(){
		var meses=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
		var codigo="<option>Mes</option>";
		for(i=0;i<meses.length;i++){
				codigo+="<option value='"+(i+1)+"'>"+meses[i]+"</option>";
			}
                document.getElementById("meses").innerHTML=codigo;
		};
		
	function ainos(){
		var aino=1940;
		var codigo="<option>Año</option>";
		for(i=new Date().getFullYear();i>=aino;i--){
			codigo+="<option>"+i+"</option>";
			}
                document.getElementById("ainos").innerHTML=codigo;
		};
                
                /* FUNCIONES PARA LAS PROVINCIAS Y POBLACIONES */
        function provincia(){
            var provincias=["GIPUZKOA","BIZKAIA","ALAVA"];
            var codigo="<option>PROVINCIA</option>";
		for(i=0;i<provincias.length;i++){
				codigo+="<option>"+provincias[i]+"</option>";
			}
            document.getElementById("provincia").innerHTML=codigo;
        };
        
        function poblaciones(){
            var gipuzkoa=["ABALTZISKETA","ADUNA","AIA","AIZARNAZABAL","ALBIZTUR","ALEGIA","ALKIZA","ALTZAGA","ALTZO","AMEZKETA","ANDOAIN","ANOETA","ANTZUOLA","ARAMA","ARETXABALETA","ARRASATE/MONDRAGÓN","ASTEASU","ASTIGARRAGA","ATAUN","AZKOITIA","AZPEITIA","BALIARRAIN","BEASAIN","BEIZAMA","BELAUNTZA","BERASTEGI","BERGARA","BERROBI","BIDEGOIAN","DEBA","DONOSTIA-SAN SEBASTIÁN","EIBAR","ELDUAIN","ELGETA","ELGOIBAR","ERRENTERIA","ERREZIL","ESKORIATZA","EZKIO-ITSASO","GABIRIA","GAINTZA","GAZTELU","GETARIA","HERNANI","HERNIALDE","HONDARRIBIA","IBARRA","IDIAZABAL","IKAZTEGIETA","IRUN","IRURA","ITSASONDO","LARRAUL","LASARTE-ORIA","LAZKAO","LEABURU","LEGAZPI","LEGORRETA","LEINTZ-GATZAGA","LEZO","LIZARTZA","MENDARO","MUTILOA","MUTRIKU","OIARTZUN","OLABERRIA","OÑATI","ORDIZIA","ORENDAIN","OREXA","ORIO","ORMAIZTEGI","PASAIA","SEGURA","SORALUZE/PLACENCIA DE LAS ARMAS","TOLOSA","URNIETA","URRETXU","USURBIL","VILLABONA","ZALDIBIA","ZARAUTZ","ZEGAMA","ZERAIN","ZESTOA","ZIZURKIL","ZUMAIA","ZUMARRAGA"];
            var alava=["ALEGRÍA-DULANTZI","AMURRIO,AÑANA","ARAMAIO","ARMIÑÓN","ARRAIA-MAEZTU","ARRAZUA-UBARRUNDIA","ARTZINIEGA","ASPARRENA","AYALA/AIARA","BAÑOS DE EBRO/MAÑUETA","BARRUNDIA","BERANTEVILLA","BERNEDO","CAMPEZO/KANPEZU","ELBURGO/BURGELU","ELCIEGO","ELVILLAR/BILAR","HARANA/VALLE DE ARANA","IRUÑA OKA/IRUÑA DE OCA","IRURAIZ-GAUNA","KRIPAN","KUARTANGO","LABASTIDA/BASTIDA","LAGRÁN","LAGUARDIA","LANCIEGO/LANTZIEGO","LANTARÓN","LAPUEBLA DE LABARCA","LAUDIO/LLODIO","LEGUTIANO","LEZA","MOREDA DE ÁLAVA","NAVARIDAS","OKONDO","OYÓN-OION","PEÑACERRADA-URIZAHARRA","RIBERA ALTA","RIBERA BAJA/ERRIBERA BEITIA","SALVATIERRA/AGURAIN","SAMANIEGO","SAN MILLÁN/DONEMILIAGA","URKABUSTAIZ","VALDEGOVÍA/GAUBEA","VILLABUENA DE ÁLAVA/ESKUERNAGA","VITORIA-GASTEIZ","YÉCORA/IEKORA","ZALDUONDO","ZAMBRANA","ZIGOITIA","ZUIA"];
            var bizkaia=["ABADIÑO","ABANTO Y CIÉRVANA-ABANTO ZIERBENA","AJANGIZ","ALONSOTEGI","AMOREBIETA-ETXANO","AMOROTO","ARAKALDO","ARANTZAZU","AREATZA","ARRANKUDIAGA","ARRATZU","ARRIETA","ARRIGORRIAGA","ARTEA","ARTZENTALES","ATXONDO","AULESTI","BAKIO","BALMASEDA","BARAKALDO","BARRIKA","BASAURI","BEDIA","BERANGO","BERMEO","BERRIATUA","BERRIZ","BILBAO","BUSTURIA","DERIO","DIMA","DURANGO","EA","ELANTXOBE","ELORRIO","ERANDIO","EREÑO","ERMUA","ERRIGOITI","ETXEBARRI","ETXEBARRIA","FORUA","FRUIZ","GALDAKAO","GALDAMES","GAMIZ-FIKA","GARAI","GATIKA","GAUTEGIZ ARTEAGA","GERNIKA-LUMO","GETXO","GIZABURUAGA","GORDEXOLA","GORLIZ","GÜEÑES","IBARRANGELU","IGORRE","ISPASTER","IURRETA","IZURTZA","KARRANTZA HARANA/VALLE DE CARRANZA","KORTEZUBI","LANESTOSA","LARRABETZU","LAUKIZ","LEIOA","LEKEITIO","LEMOA","LEMOIZ","LEZAMA","LOIU","MALLABIA","MAÑARIA","MARKINA-XEMEIN","MARURI-JATABE","MENDATA","MENDEXA","MEÑAKA","MORGA","MUNDAKA","MUNGIA","MUNITIBAR-ARBATZEGI GERRIKAITZ","MURUETA","MUSKIZ","MUXIKA","NABARNIZ","ONDARROA","OROZKO","ORTUELLA","OTXANDIO","PLENTZIA","PORTUGALETE","SANTURTZI","SESTAO","SONDIKA","SOPELANA","SOPUERTA","SUKARRIETA","TRUCIOS-TURTZIOZ","UBIDE","UGAO-MIRABALLES","URDULIZ","URDUÑA-ORDUÑA","VALLE DE TRÁPAGA-TRAPAGARAN","ZALDIBAR","ZALLA","ZAMUDIO","ZARATAMO","ZEANURI","ZEBERIO","ZIERBENA","ZIORTZA-BOLIBAR"];
            var pro = document.getElementById("provincia");
            var codigo = "<option>POBLACIÓN</option>";
            //document.writeln(pro.options[pro.selectedIndex].text);
            if(pro.options[pro.selectedIndex].text == "PROVINCIA"){
                document.getElementById("poblacion").disabled=true;
            }else{
                if(pro.options[pro.selectedIndex].text == "GIPUZKOA"){
                    document.getElementById("poblacion").disabled=false;
                    for(i=0;i<gipuzkoa.length;i++){
                                    codigo+="<option>"+gipuzkoa[i]+"</option>";
                            }
                
                }
                if(pro.options[pro.selectedIndex].text == "ALAVA"){
                    document.getElementById("poblacion").disabled=false;
                    for(i=0;i<alava.length;i++){
                                    codigo+="<option>"+alava[i]+"</option>";
                            }
                
                }
                if(pro.options[pro.selectedIndex].text == "BIZKAIA"){
                    document.getElementById("poblacion").disabled=false;
                    for(i=0;i<bizkaia.length;i++){
                                    codigo+="<option>"+bizkaia[i]+"</option>";
                            }
                
                }
            }
            document.getElementById("poblacion").innerHTML=codigo;
            document.getElementById("poblacion").selectedIndex.text=<%=user.getProvincia()%>;
        };
        function comprobarCP(campo){
            if(campo.length<5){
                document.getElementById("cp").style.background="#FF0";
            }else{
                document.getElementById("cp").style.background="#FFF";
            }
        };
        function comprLongNick(){
                <%--document.getElementById("validar_nick").value=document.getElementById("nick").value;
            alert("Campo hidden:"+document.getElementById("validar_nick").value);
          //  document.getElementById("nickform").submit();
            document.forms["nickform"].submit();
                
                <% 
                  
                   reg.nickDisponible(reg.nick); 
                   System.out.println("USUARIOEXISTENTE DE MIERDA:"+reg.usuarioExistente);
                   int val=reg.usuarioExistente;
                   System.out.println("USUARIOEXISTENTE DE MIERDA:"+val);
                      switch (val){
                          case 1:  
                              System.out.println("EXISTO");
                               
                                                          break;
                              
                            
                              
                          case 0:  
                                 System.out.println("NOOO EXISTO");
                                    %> document.getElementById("aviso").style.visibility="hidden";<%
                              break;
                          default: 
                           System.out.println("ME RIO EN TU CARA");
                              break;
}--%>
                     
                        
              
           if(nick.value.length<4){
                document.getElementById("nick").style.color="#FF0000";
            }else{
                document.getElementById("nick").style.color="#000";
            }
        }
       
        function comprLongPass(){
            if(pass.value.length<6){
                document.getElementById("pass").style.color="#FF0000";
            }else{
                document.getElementById("pass").style.color="#000";
            }
        }
        
        function validarPass(){
            var pass1=document.getElementById("pass").value;
            var pass2=document.getElementById("re_password").value;
            if(pass1 !== pass2){
                alert('Las contraseñas no coinciden!');
        }
    }
    
        function validarEmail(email){
            var email=document.getElementById("email").value;
            expr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if ( !expr.test(email) )
            alert("Error: La dirección de correo " + email + " es incorrecta.");
}
    
    
        </script>
        
        <fieldset id="actualizar_datos"><legend>Mis Datos Personales</legend>
            <br>
            <form id="personales" name="personales" action="control.jsp" method="post">
                    <label>Usuarios: </label><input name="nick" type="text" value="<%=user.getNick()%>" disabled="true"/><br><br>
                    <label>Nombres: </label><input name="nombre" type="text" value="<%=user.getNombre()%>" disabled="true"/><br><br>
                    <label>Apellidos: </label><input name="apellidos" type="text" value="<%=user.getApellidos()%>" disabled="true"/><br><br>
                    <label>DNI: </label><input name="dni" type="text" value="<%=user.getDni()%>" disabled="true"/><br><br>
                    <label>Fecha de Naciemto: </label><input type="text" value="<%=user.getNacimiento()%>" disabled="true"/><br><br>
                    <input type="submit" class="buttonM" name="gdatospersonales" value="Guardar" disabled="true"/>
                    <input type="button" class="buttonM" value="Modificar" onClick="datosPersonales();"/>
                </form><br>
        </fieldset>
        <br><br>
        

        <fieldset id="actualizar_datos"><legend>Cambiar contraseña</legend>
            <br>
            <form id="cambiarpass" action="control.jsp" method="POST" onsubmit="calcMD52()">
                <label> Contraseña actual </label> <input type="password" id="passvie" name="passvie"/><br><br>
                <label> Contraseña nueva </label> <input type="password" id="passnue" name="passnue"/><br><br>
                <label> Repita contraseña nueva </label> <input type="password" id="passnue2" name="passnue2"  onchange="passigual()"/> <br><br>
                
                <p><%=reg.mensajes %></p>
                <input type="submit" class="buttonM" name="gpass" value="Guardar"/>
                <%reg.mensajes="";%>
            </form><br>
        </fieldset><br><br>
        

        <fieldset id="actualizar_datos"><legend>Mis Datos de Contacto</legend>

            <br>
                <form>
                    <label>Dirección: </label><input type="text" name="direccion" value="<%=user.getDireccion()%>" disabled="true"/><br><br>
                    <label>Provincia: </label><input type="text" value="<%=user.getProvincia()%>" disabled="true"/><!-- PETICIÓN DE PROVINCIA Y POBLACIÓN -->
                    
                    <select id="provincia" name="provincia" onchange="poblaciones();" required>
                                <script>
                                provincia();
                                </script>
                    </select><br><br>
                    <label>Población: </label><input type="text" value="<%=user.getPoblacion()%>" disabled="true"/>
                    <select id="poblacion" name="poblacion" disabled required>
                                <script>
                                poblaciones();
                                </script>
                    </select><br><br>
                    <label>CP: </label><input type="text" name="cp" value="<%=user.getCp()%>" disabled="true"/><br><br>
                    <label>Correo Electronico: </label><input type="text" name="correo" value="<%=user.getEmail()%>" disabled="true"/><br><br>
                    <label>Teléfono: </label><input type="text" name="telefono" value="<%=user.getTelefono()%>" disabled="true"/><br><br>
                    <input type="submit" class="buttonM" name="gdatoscontacto" value="Guardar" disabled="true"/>
                    <input type="button" class="buttonM" value="Modificar" onclick="datosContacto();"/>
                </form><br>
        </fieldset><br><br>
        
        <fieldset id="actualizar_datos"><legend>Mi Crédito</legend>
            <form action="control.jsp" method="post">
                    <label>Crédito: </label><input type="text" value="<%=user.getCredito()%>" disabled="true"/><br><br>
                    <input type="submit" class="buttonM" name="addCreditos" value="Añadir"/>
                </form><br>
        </fieldset><br><br>
      </section>
      <!-- INCLUDE PARA METER EL FOOTER -->
      <jsp:include page="includes/footer.jsp"/>  
        
    </body>
</html>
